#include "main.h"
#include "mem.h"//for memGetUsedBytes
#include "led.h"//for ledInit/newLed
#include <stdio.h> //for printf
#include "halio.h"//for halIoWrite
#include "halmem.h" //for halMemInit

#include "focHal.h"

static led_p ledSys = NULL;

// LED闪烁两次，提供给应用程序使用的接口，可用于收发数据时调用
void ledFlicker(void)
{
    ledSys->run(ledSys, LED_FLICKER_TWICE);
}

void appInit(void)
{
    halMemInit();

    ledInit(halIoWrite);
    ledSys = newLed(PC(13), false, NULL);

    //todo: new other objects
    focHalInit();

    // 保持在函数末尾，用以统计创建全部对象所用的堆内存
    uint32_t usedBytes = memGetUsedBytes();
    printf("Heap memory used: %d bytes.\n", (int)usedBytes);
}

void appLoop(void)
{
    ledLoop(HAL_GetTick());

    //foc运行
    focHalLoop();
}
